package com.ksd.web.controller.tool;

import com.ksd.common.utils.StringUtils;
import com.ksd.system.domain.SysFreqOne;
import com.ksd.system.domain.SysFreqTwice;

import java.util.ArrayList;
import java.util.List;

public class RefuseList {
    public static List<SysFreqOne> customSortOne(List<SysFreqOne> list, SysFreqOne targetFreq) {
        List<SysFreqOne> smallerThanTarget = new ArrayList<>();
        List<SysFreqOne> largerThanTarget = new ArrayList<>();

        if (StringUtils.isNotNull(targetFreq)) {
            Long number = targetFreq.getNumber();
            // 找到目标对象，并将其他对象分类
            for (SysFreqOne obj : list) {
                Long number1 = obj.getNumber();
                if (number1 < number) {
                    smallerThanTarget.add(obj);
                } else if(number1 > number) {
                    largerThanTarget.add(obj);
                }
            }
        }else{
            System.out.println("没有目标频道,直接返回排序后的频道频率个数:"+list.size());
            return list;
        }

        // 构建新的列表
        List<SysFreqOne> resultList = new ArrayList<>();
        if (StringUtils.isNotNull(targetFreq)) {
            resultList.add(targetFreq);
        }
        if (StringUtils.isNotNull(largerThanTarget)) {
            resultList.addAll(largerThanTarget);
        }
        if (StringUtils.isNotNull(smallerThanTarget)) {
            resultList.addAll(smallerThanTarget);
        }
        System.out.println("直播板卡1排序后的频道频率个数:"+resultList.size());
        return resultList;
    }

    public static List<SysFreqTwice> customSortTwice(List<SysFreqTwice> list, SysFreqTwice targetFreq) {
        List<SysFreqTwice> smallerThanTarget = new ArrayList<>();
        List<SysFreqTwice> largerThanTarget = new ArrayList<>();

        if (StringUtils.isNotNull(targetFreq)) {
            Long number = targetFreq.getNumber();
            // 找到目标对象，并将其他对象分类
            for (SysFreqTwice obj : list) {
                Long number1 = obj.getNumber();
                if (number1 < number) {
                    smallerThanTarget.add(obj);
                } else if(number1 > number) {
                    largerThanTarget.add(obj);
                }
            }
        }else{
            System.out.println("没有目标频道,直接返回排序后的频道频率个数:"+list.size());
            return list;
        }

        // 构建新的列表
        List<SysFreqTwice> resultList = new ArrayList<>();
        if (StringUtils.isNotNull(targetFreq)) {
            resultList.add(targetFreq);
        }
        if (StringUtils.isNotNull(largerThanTarget)) {
            resultList.addAll(largerThanTarget);
        }
        if (StringUtils.isNotNull(smallerThanTarget)) {
            resultList.addAll(smallerThanTarget);
        }
        System.out.println("直播板卡2排序后的频道频率个数:"+resultList.size());
        return resultList;
    }
}
